import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Delete from '#cpt/temp/Delete'
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '标本箱号',		name: 'box_number' },
			{ label: '运输方式',		name: 'ship_type',	type: 'select', idStr:'code', loading:true },
			{ label: '日期',			names: ['startTime','endTime'],		type: 'date-range' },
		],
		// 提交表单列表
		formData : [
			{ label: '我的标本箱号',	name: 'box_number', 	full:true, required:true,  },
			{ label: '运输方式',		name: 'ship_type', 		full:true, type: 'select', idStr:'code', required:true },
			//{ label: '定位方式',		name: 'role_type', 	half:true, type: 'select', required:true, idStr:'code' },
			{ label: '起始位置',		name: 'areaData', 		full:true, type:'address', required:true, },
			{ label: '详细地址', 	name: 'address', 		full:true, type:'textarea', required:true,},
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	 getSelect = async () => {
	  const { forms,formData } = this.state
	  $cache.then( async f => {
			// 医院名称
			$fn.setRows( [formData,forms], 'ship_type', await f.getDicCache({ code:43600 }) )
			this.setState({ forms })
	  })
	 }
	// paging
	fetch = () => $fn.fetch.call(this,'gps-follow/index')
	
	// 表单
	cols = [
		{ title: '标本箱号',		dataIndex: 'box_number', 			width:150 },
		{ title: '当前位置', 	dataIndex: 'current_address', 		width:200 },
		{ title: '录入时间', 	dataIndex: 'gps_time', 				...$fn.table.time },
		{ title: '运输人', 		dataIndex: 'receiver_name', 		...$fn.table.name },
		{ title: '运输方式',		dataIndex: 'ship_type_name', 		width:100 },
		{ title: '状态', 		dataIndex: 'follow_status_name', 	width:150 },
		TableControls.controls.call(this)
	]
	// 表格操作按钮
		table_controls = (text,{ uuid,pic_name}) => {
			return [
				TableControls.click.call(this, '查看轨迹', ()=>{} )
			]
		}
	// 操作按钮
	controls = () => {
		return [
			Controls.click.call(this, '手动录入', ()=>this.modal.open({formRef: this.formRef}), {code: 'F1'} ),
			this.onDel(),													// 删除
		]
	}
	// 删除
	onDel = uuid => Delete.call(this, 'gps-follow/delete', { uuid,isKeys: !uuid })	
	
	render(){
			return (
				<>
					<Page title='物流跟踪'  controls={this.controls()} >
						{/* 搜索 */}
						{ SearchForm.call(this) }
						{/* 表格 */}
						{ Table.call(this, { isInit: window.isInit }) }
					</Page>
					{FormModal.call(this,{ title:'手动录入', labelWidth:'s7', api: 'gps-follow/add' })}
				</>
			)
		}
	}
	
	export default Index